package com.ltg.urban.domain.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ltg.framework.util.http.PageInfo;
import com.ltg.framework.util.http.Result;
import com.ltg.urban.domain.project.data.response.CapitalDetailResp;
import com.ltg.urban.domain.project.data.response.UrbanCapitalPageResp;
import com.ltg.urban.domain.project.data.response.UrbanProjectCapitalResp;
import com.ltg.urban.domain.project.entity.UrbanProjectCapital;
import com.ltg.urban.domain.project.entity.UrbanProjectCapitalDetail;
import com.ltg.urban.domain.project.entity.UrbanProjectUser;
import com.ltg.urban.domain.project.mapper.UrbanProjectCapitalDetailMapper;
import com.ltg.urban.domain.project.mapper.UrbanProjectCapitalMapper;
import com.ltg.urban.domain.project.mapper.UrbanProjectUserMapper;
import com.ltg.urban.domain.project.service.UrbanProjectUserService;
import com.ltg.urban.domain.sys.data.response.CurrentUserHolder;
import com.ltg.urban.domain.sys.data.response.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p> ClassName: UrbanProjectUserServiceImpl </p>
 * <p> Package: com.ltg.urban.domain.project.service.impl </p>
 * <p> Description: </p>
 * <p></p>
 *
 * @Author: LTG
 * @Create: 2023/2/26 - 16:50
 * @Version: v1.0
 */
@Service
@RequiredArgsConstructor
public class UrbanProjectUserServiceImpl extends ServiceImpl<UrbanProjectUserMapper, UrbanProjectUser> implements UrbanProjectUserService {

    private final UrbanProjectCapitalMapper urbanProjectCapitalMapper;
    private final UrbanProjectCapitalDetailMapper urbanProjectCapitalDetailMapper;


    @Override
    public PageInfo<UrbanCapitalPageResp> pageList(Page<UrbanCapitalPageResp> page, String keyword, Integer approveResult) {
        UserInfo currentUser = CurrentUserHolder.getCurrentUser();
        page = urbanProjectCapitalMapper.pageList(page,currentUser.getUser().getId(),currentUser.getRole().getRoleName(),keyword,approveResult);
        return new PageInfo<>(page);
    }

    @Override
    public Result<CapitalDetailResp> detail(Page<UrbanProjectCapitalDetail> page, Long capitalId) {
        CapitalDetailResp capitalDetailResp = new CapitalDetailResp();
        UrbanProjectCapitalResp capitalResp = urbanProjectCapitalMapper.detail(capitalId);
        LambdaQueryWrapper<UrbanProjectCapitalDetail> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UrbanProjectCapitalDetail::getCapitalId, capitalId);
        page = urbanProjectCapitalDetailMapper.selectPage(page, wrapper);
        capitalDetailResp.setDetailPage(page);
        capitalDetailResp.setCapitalResp(capitalResp);
        return Result.success(capitalDetailResp);
    }


}
